<template>
	<view>
		<u-collapse ref='coll' :value="['1','2']" @change="handleOpenChange">
			<u-collapse-item name="1" title="oun光功率信息" icon="order" ref="collapseHeight">
				<u-cell-group>
					<u-cell title="光功率" :use-label-slot="true">
						<span slot="label" class="cell-label">{{faultdata.Opticalpower}}</span>
					</u-cell>
					<u-cell title="端口" :use-label-slot="true">
						<span slot="label" class="cell-label">{{faultdata.Fdn}}</span>
						<u-button type="primary" @click="toCheck" slot="right-icon">检查光功率</u-button>
					</u-cell>
					<u-cell title="物理地址" :use-label-slot="true">
						<span slot="label" class="cell-label">{{faultdata.Mac}}</span>
					</u-cell>
					<u-cell title="地址" :use-label-slot="true">
						<span slot="label" class="cell-label">{{faultdata.Addr || ""}}</span>
					</u-cell>
				</u-cell-group>
			</u-collapse-item>
			<u-collapse-item name="2" title="olt设备信息" icon="order" ref="collapseHeight">
				<u-cell-group>
					<u-cell title="别名" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.AlienName}}</span>
					</u-cell>
					<u-cell title="Ip" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Ip || " "}}</span>
					</u-cell>
					<u-cell title="地市" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.City || " "}}</span>
					</u-cell>
					<u-cell title="公司" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Company || " "}}</span>
					</u-cell>
					<u-cell title="地址" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Addr || " "}}</span>
					</u-cell>
					<u-cell title="机房" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Room || " "}}</span>
					</u-cell>
					<u-cell title="厂商" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Factory || " "}}</span>
					</u-cell>
					<u-cell title="业务类型" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Business || " "}}</span>
					</u-cell>
					<u-cell title="设备型号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Model || " "}}</span>
					</u-cell>
					<u-cell title="网络类型" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.NetType || " "}}</span>
					</u-cell>
					<u-cell title="ONU数量" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.ONUnum || " "}}</span>
					</u-cell>
					<u-cell title="软件版本" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Sofeversion || " "}}</span>
					</u-cell>
					<u-cell title="类型" :use-label-slot="true">
						<span slot="label" class="cell-label">{{equdata.Type || " "}}</span>
					</u-cell>
				</u-cell-group>
			</u-collapse-item>
			<!-- 		<u-button type="error" :plain="true" v-if="user.Roles.indexOf('故障填报角色')!=-1 || user.Roles.indexOf('故障审核角色')!=-1"
			@click="delmodalShow = true">删除</u-button> -->
		</u-collapse>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		mapGetters
	} from 'vuex'
	import {
		GetProtOpticalPowerList,
		CheckOnuPower
	} from '@/common/api.js'
	export default {
		data() {
			return {
				faultid: "",
				faultdata: [],
				equdata: [],
				modalShow: false,
				delmodalShow: false,
				user: {},
			}
		},
		onLoad(option) {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.faultid = option.id
			this.getlist(this.faultid)
		},
		methods: {
			async getlist(id) {
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: id
				})
				await GetProtOpticalPowerList(para).then(res => {
					this.faultdata = res.data[0]
					this.equdata = res.data[0].Equ
				})
			},
			del() {
				let ids = []
				ids.push(this.faultid)
				delfault(ids).then((res) => {
					if (res == true)
						uni.navigateBack()
				})
			},
			toCheck() {
				CheckOnuPower(this.faultdata).then((res) => {
					if(res >= -25){
						this.$refs.uToast.show({
							message: '光功率为:' + res,
							type: 'success',
							position: 'top',
							duration: 4000
						})
					}else if(res < -25){
						this.$refs.uToast.show({
							message: '光功率为:' + res,
							type: 'error',
							position: 'top',
							duration: 4000
						})
					}
				})
			},
			handleOpenChange() {
			      let long = this.$refs.collapseHeight.length;
			      setTimeout(() => {
			        for (let i = 0; i < long; i++) {
			          this.$refs.collapseHeight[i].queryRect(); // 计算高度
			        }
			      }, 50);
			    },
		}
	}
</script>
<style>
	.cell-label {
		margin-top: 10px;
		font-size: 14px;
		color: #909193;
	}
</style>